import request  from "@/utils/request";
import { defineStore } from "pinia";
import { BannerItem , ApiRes , GoodItem , HotGoods, Brand, HomeProduct, Special} from '@/types/data'

export default defineStore('home',{
    state(){
        return{
            bannerList:[] as  BannerItem[],
            homeNewGoodList: []  as GoodItem[],
            hotGoodList: [] as HotGoods[],
            brandList: [] as Brand[],  // 品牌数据
            productList: [] as HomeProduct[],
            specialList: [] as Special[],
        }
    },
    actions:{
    async getBennerList(){
    const res = await request.get<ApiRes<BannerItem[]>>('/home/banner')
    this.bannerList = res.data.result
    //  console.log( this.bannerList);
    },
    async getHomeNewGoodList(){
    setTimeout(async ()=>{
        const res = await request.get<ApiRes<GoodItem[]>>('/home/new')
        this.homeNewGoodList=res.data.result
    },5000)

    },
    async getHotList() {
        setTimeout( async()=>{
        const res = await request.get<ApiRes<HotGoods[]>>('/home/hot')
        this.hotGoodList = res.data.result
    },5000)
    },
    async getBrandList() {
        setTimeout(async ()=>{
            const res = await request.get<ApiRes<Brand[]>>('/home/brand')
            console.log(res)
            this.brandList = res.data.result
        },5000)
    },
    async getProductList() {
    setTimeout(async ()=>{
        const res = await request.get<ApiRes<HomeProduct[]>>('/home/goods')
        this.productList = res.data.result
    },5000)
    },
    async getSpecialList() {
        setInterval(async ()=>{
            const res = await request.get<ApiRes<Special[]>>('/home/special')
            this.specialList = res.data.result
        },5000)
      },
    }
})